PowerTCP Mail for .NET
Receive(Byte[],Int32,Int32,SocketFlags) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Tcp Class > Receive Method : Receive(Byte[],Int32,Int32,SocketFlags) Method




buffer
Destination memory location to store received data.
offset
Starting offset within buffer for filling.
count
Maximum number of bytes to receive.
socketFlags
A bitwise combination of special use receiving parameters.
Receive data from the host, specifying a buffer, offset, count and SocketFlags value.

Syntax

Visual Basic (Declaration) 
<DescriptionAttribute("Receive data into your buffer.")>
Public Overloads Function Receive( _
   ByVal buffer() As Byte, _
   ByVal offset As Integer, _
   ByVal count As Integer, _
   ByVal socketFlags As SocketFlags _
) As Segment
Visual Basic (Usage)Copy Code
Dim instance As Tcp
Dim buffer() As Byte
Dim offset As Integer
Dim count As Integer
Dim socketFlags As SocketFlags
Dim value As Segment
 
value = instance.Receive(buffer, offset, count, socketFlags)
C# 
[DescriptionAttribute("Receive data into your buffer.")]
public Segment Receive( 
   byte[] buffer,
   int offset,
   int count,
   SocketFlags socketFlags
)
Managed Extensions for C++ 
[DescriptionAttribute("Receive data into your buffer.")]
public: Segment* Receive( 
   byte[]* buffer,
   int offset,
   int count,
   SocketFlags socketFlags
) 
C++/CLI 
[DescriptionAttribute("Receive data into your buffer.")]
public:
Segment^ Receive( 
   array<byte>^ buffer,
   int offset,
   int count,
   SocketFlags socketFlags
) 

Parameters

buffer
Destination memory location to store received data.
offset
Starting offset within buffer for filling.
count
Maximum number of bytes to receive.
socketFlags
A bitwise combination of special use receiving parameters.

Return Value

A Segment object encapsulating the data received.

Exceptions

ExceptionDescription
System.IO.IOExceptionThe stream is not Readable.
System.ArgumentNullExceptionbuffer is null.
System.ArgumentOutOfRangeExceptionoffset or count is less than 0.
System.ArgumentExceptionoffset + count is greater than the length of buffer.
System.Net.Sockets.SocketExceptionThe socket is not connected.

Example

The following example demonstrates sending bytes to the server with a SocketFlag option.
Visual BasicCopy Code
Private Sub Test()
   ' Connect to an echo port
   Tcp1.Connect("atropos", 7)

   Dim sendbuffer() As Byte = System.Text.Encoding.Default.GetBytes("abcdefg")

   ' Send some bytes with "OutOfBand" SocketFlag option
   Tcp1.Send(sendbuffer, 0, sendbuffer.Length, SocketFlags.OutOfBand)

   Dim recvbuffer(sendbuffer.Length) As Byte

   ' Server will echo the bytes back. Receive the bytes.
   Tcp1.Receive(recvbuffer, 0, recvbuffer.Length, SocketFlags.None)

   ' Close the connection.
   Tcp1.Close()
End Sub
C#Copy Code
private void Test()
{
   // Connect to the echo port
   tcp1.Connect("atropos", 7);

   byte[] sendbuffer = System.Text.Encoding.Default.GetBytes("abcdefg");

   // Send some bytes with "OutOfBand" SocketFlag option
   tcp1.Send(sendbuffer, 0, sendbuffer.Length, SocketFlags.OutOfBand);

   byte[] recvbuffer = new byte[sendbuffer.Length];

   // Server will echo the bytes back. Receive the bytes.
   tcp1.Receive(recvbuffer, 0, recvbuffer.Length, SocketFlags.None);

   // Close the connection.
   tcp1.Close();
}

Remarks

After connecting, data can be received using the Tcp.Recieve method. All Tcp.Receive methods return a Segment object, encapsulating the data received. In order to access the data, simply access the properties of the Segment object returned such as Segment.Buffer (to access the data in a byte array) or Segment.ToString (to access the data as a string).

This method is the only way to receive data from a host while specifying a SocketFlags parameter.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.